#define _CRT_SECURE_NO_WARNINGS 1
#include"sort.h"

void testInsertSort()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	InsertSort(a, n);
	printf("InserSort:");
	printSort(a, n);
}

void testHeapSort()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	HeapSort(a, n);
	printf("HeapSort:");
	printSort(a, n);
}

void testShellSort()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	ShellSort(a, n);
	printf("ShelSort:");
	printSort(a, n);
}

void CompareSort()
{
	srand((unsigned)time(0));
	 const int n = 1000000;
	
	int* a1 = (int*)malloc(sizeof(int) * n);
	int* a2 = (int*)malloc(sizeof(int) * n);
	int* a3 = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		a1[i] = rand() + i;
		a2[i] = a1[i];
		a3[i] = a1[i];
	}
	
	int begin1 = clock();
	//InsertSort(a1,n);
	int end1 = clock();
	printf("InsertSort:%dms\n", end1-begin1);
	
	int begin2 = clock();
	HeapSort(a2, n);
	int end2 = clock();
	printf("HeapSort:%dms\n", end2-begin2);

	int begin3 = clock();
	ShellSort(a3, n);
	int end3 = clock();
	printf("ShellSort:%dms\n", end3-begin3);

	free(a1);
	free(a2);
	free(a3);
}

int main()
{
	/*testInsertSort();
	testHeapSort();
	testShellSort();*/
	CompareSort();
	return 0;
}